package com.ruoyi.expertmodel.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.expertmodel.domain.HealthModel;
import com.ruoyi.expertmodel.mapper.HealthModelMapper;
import com.ruoyi.expertmodel.service.HealthModelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@Service
public class HealthModelServiceImpl extends ServiceImpl<HealthModelMapper, HealthModel> implements HealthModelService {

    @Resource
    private HealthModelMapper healthModelMapper;


    @Override
    public List<HealthModel> queryHealthModel(HealthModel healthModel) {
        return healthModelMapper.queryHealthModel(healthModel);
    }

    @Override
    public CompletableFuture<List<HealthModel>> queryHealthModel2(HealthModel healthModel) {
        return CompletableFuture.supplyAsync(() -> {

            return healthModelMapper.queryHealthModel(healthModel);
        });
    }

    @Override
    public boolean deleteHealthModel(HealthModel healthModel) {

        return healthModelMapper.deleteHealthModel(healthModel.getId())>0;
    }


    @Transactional
    @Override
    public boolean batchImport(List<HealthModel> healthModels) {
        boolean flag = true;
        for(HealthModel e :healthModels){
            try{
                boolean save = this.save(e);

                if(!save){
                    flag=false;
                }
            }catch (Exception e1){
                flag = false;

            }

        }
        return flag;
    }

    @Override
    public void copyHealthModel(HealthModel healthModel) {
        healthModelMapper.insert(healthModel);
    }


}
